<template>
	<view class="container position-relative">
		<view class="" v-if="is_flag">
			<image v-if="nav_type==2" @click="toPage('/filePage/pages/live/live',1)"
				:src="baseUrl + '/static/broadcast.png'" mode=""
				style="position: fixed;right: 50rpx;bottom: 50rpx;width: 112rpx;height: 112rpx;z-index: 2;"></image>
			<image v-if="nav_type==1||nav_type==3"
				@click="toPage('/filePage/pages/release/release?nav_type=' + nav_type,1)"
				:src="baseUrl + '/static/send.png'" mode=""
				style="position: fixed;right: 50rpx;bottom: 50rpx;width: 112rpx;height: 112rpx;z-index: 2;"></image>
		</view>

		<view class="bg-white" style="min-height: 210rpx;">
			<kg-custom :isBack="false" bgColor="bg-white">
				<block slot="left">
					<view class="flex justify-start align-center bg-F4F4F4 padding-left round margin-left-sm"
						style="height: 70rpx;width: 460rpx;">
						<image :src="baseUrl + '/static/search_for.png'" mode="" style="width: 25rpx;height: 25rpx;">
						</image>
						<input type="text" value="" v-model="title" confirm-type="search" @confirm="search"
							class="text-13 f-grow1 padding-left-sm" placeholder="搜索商学院主题" />
					</view>
				</block>
			</kg-custom>
			<view v-if="is_flag" class="flex justify-between align-center text-15 text-221815 text-bold nav">
				<view class="padding-sm" :class="{'on':nav_type==1}" @click="changeNavType(1)">
					短视频广场
				</view>
				<view class="padding-sm" :class="{'on':nav_type==2}" @click="changeNavType(2)">
					直播Live
				</view>
				<view class="padding-sm" :class="{'on':nav_type==3}" @click="changeNavType(3)">
					方案中心
				</view>
				<view v-if="is_flag" class="padding-sm" :class="{'on':nav_type==4}" @click="changeNavType(4)">
					培训中心
				</view>
			</view>
			<view v-if="classification1.length>0&&is_flag>0"
				class="text-666 position-relative text-df flex justify-between align-center padding-left-sm padding-right-sm">
				<scroll-view scroll-x class="bg-white nav text-666" scroll-with-animation :scroll-left="scrollLeft">
					<view class="cu-item" :class="TabCur==''?'text-333 text-bold':''" @click="tabSelect('',0)">
						<view class="flex justify-center align-center">
							<view class="margin-right-xs">
								全部
							</view>
						</view>
					</view>
					<view class="cu-item" :class="item.id==TabCur?'text-333 text-bold':''"
						v-for="(item,index) in classification1" @click="tabSelect(item,index + 1)">
						<view class="flex justify-center align-center">
							<view class="margin-right-xs">
								{{item.name}}
							</view>
							<image v-if="nav_type==1 || nav_type==3" :src="baseUrl + '/static/up.png'" mode=""
								style="width: 26rpx;height: 26rpx;"></image>

						</view>

					</view>
				</scroll-view>
				<view class="bg-white" style="position: absolute;top: 90rpx;left: 0;right: 0;z-index: 10;"
					v-if="is_show">
					<view class="flex justify-between align-center padding solid-bottom"
						v-for="item in  classification2" :class="{'color':classificationId==item.id}"
						@click="changeclassification(item.id)">
						<view class="">
							{{item.name}}
						</view>
						<image v-if="classificationId==item.id" :src="baseUrl+'/static/selected.png'" mode=""
							style="width: 36rpx;height: 36rpx;min-width: 36rpx;"></image>
						<image v-else :src="baseUrl+'/static/unselected.png'" mode=""
							style="width: 36rpx;height: 36rpx;min-width: 36rpx;"></image>
					</view>
				</view>
			</view>
		</view>
		<!-- <scroll-view scroll-y show-scrollbar refresher-enabled style="height: calc(100vh - 346rpx);"> -->
		<view class="list margin-left-sm margin-right-sm margin-bottom-sm">
			<!-- <eiml-flow-layout :list="list"></eiml-flow-layout> -->
			<view class="" v-if="nav_type==2||nav_type==1">
				<view v-for="(item,index) in list"
					@click="toPage(nav_type==2 ? '/filePage/pages/live-detail/live-detail?id=' + item.id : '/filePage/pages/video-detail/video-detail?index=' + index+'&id=' + item.id +'&typeId=' + TabCur + '&typeChildId=' + classificationId + '&typeName=' + typeName ,item)"
					:class="{'margin-left14':index%2!=0}" class="item position-relative bg-white margin-top-sm"
					style="width: 348rpx;min-width: 348rpx;border-radius: 16px 16px 0px 0px;display: inline-block;">
					<image v-if="nav_type==1" :src="baseUrl + '/static/Play.png'" mode=""
						style="position: absolute;top: 18rpx;right: 18rpx;width: 42rpx;height: 42rpx;z-index: 2;">
					</image>
					<view class="" v-if="nav_type==1&&item.price">
						<view class="bg-color text-sm text-white radius10"
							style="position: absolute;top: 20rpx;left: 20rpx;z-index: 2;padding: 4rpx 20rpx;">
							<text v-if="item.payStatus">已付费</text>
							<text v-else>付费</text>
						</view>
					</view>
					<!-- <view class="" v-if="nav_type==2&&item.chargeStatus==1">
						<view v-if="item.chargeAmount" class="bg-color text-sm text-white radius10"
							style="position: absolute;top: 20rpx;right: 20rpx;z-index: 2;padding: 4rpx 20rpx;">
							<text v-if="item.payStatus">已付费</text>
							<text v-else>付费</text>
						</view>
						<view v-if="nav_type==2" class="flex justify-center align-center"
							style="background: rgba(0,0,0,.5);width: 126rpx;height: 42rpx;position: absolute;top: 20rpx;left: 20rpx;z-index: 2;">
							<view class="round"
								style="width: 10rpx;height: 10rpx;background: #16D91F;margin-right: 14rpx;">

							</view>
							<view class="text-sm text-white">
								直播中
							</view>
						</view>
					</view> -->
					<cover-view v-if="nav_type==2">
						<cover-view v-if="item.chargeAmount&&item.chargeStatus==1"
							class="bg-color text-sm text-white radius10"
							style="position: absolute;top: 20rpx;right: 20rpx;z-index: 2;padding: 4rpx 20rpx;">
							{{item.payStatus?'已付费':'付费'}}
						</cover-view>
						<cover-view class="flex justify-center align-center"
							style="background: rgba(0,0,0,.5);width: 126rpx;height: 42rpx;position: absolute;top: 20rpx;left: 20rpx;z-index: 2;">
							<cover-view class="round"
								style="width: 10rpx;height: 10rpx;background: #16D91F;margin-right: 14rpx;">

							</cover-view>
							<cover-view class="text-sm text-white">
								直播中
							</cover-view>
						</cover-view>
					</cover-view>
					<!--  #ifdef  MP-WEIXIN-->
					<live-player v-if="nav_type==2" :src="item.pullRtmpUrl" muted autoplay
						style="width: 100%;height: 348rpx;" />
					<!--  #endif -->
					<!--  #ifdef  APP-PLUS-->
					<image v-if="nav_type==2" :src="item.coverUrl?item.coverUrl:defaultImage" mode=""
						style="width: 100%;height: 348rpx;z-index: 999;">
					</image>

					<!--  #endif -->
					<view class="" v-if="nav_type!=2">

						<!--  #ifdef  MP-WEIXIN-->
						<video v-if="item.videoUrl" :src="item.videoUrl" :controls="false" :show-center-play-btn="false"
							object-fit="cover" class="width-sub"></video>
						<!--  #endif -->

						<!--  #ifdef  APP-PLUS-->
						<image v-if="item.videoUrl" :src="item.coverUrl" mode="" class="width-sub"
							style="height: 348rpx;"></image>
						<!--  #endif -->

						<image v-else :src="item.coverImg" mode="" class="width-sub" style="height: 348rpx;">
						</image>

					</view>

					<view class="padding-sm position-relative">
						<view v-if="nav_type==2" class="text-sm text-white"
							style="position: absolute; bottom:160rpx;left: 20rpx;z-index: 99999;">
							{{item.onLineNum}}人在看
						</view>
						<view class="text-cut text-15 text-333">
							{{item.title}}
						</view>
						<view class="flex justify-between align-center margin-top-sm">
							<view class="flex justify-start align-center text-cut">
								<image :src="item.headImg" mode="" class="round"
									style="width: 34rpx;height: 34rpx;min-width: 34rpx;">
								</image>
								<view class="" style="margin-left: 12rpx;">
									{{item.nickName}}
								</view>
							</view>
							<view class="color text-cut">
								{{item.typeName}}
							</view>
						</view>
					</view>

				</view>
			</view>
			<view class="flex justify-between" v-else-if="nav_type==3">
				<view class="left" style="width: 348rpx;min-width: 348rpx;">
					<view class="" v-for="(item,index) in left_list">
						<view
							@click="toPage('/filePage/pages/file-detail/file-detail?id=' + item.id + '&nav_type=' + nav_type,item)"
							v-if="item.fileType!=1"
							class="item position-relative bg-white margin-top-sm width-sub radius5">
							<view v-if="item.fileType==2"
								class="flex justify-start align-center margin-top-sm padding-sm">
								<image :src="baseUrl+'/static/businessschool1.png'" mode=""
									style="width: 48rpx;height: 66rpx;margin: 24rpx 30rpx 0;min-width: 48rpx;"></image>
								<view class="text-cut">
									<view class="text-15 text-bold text-cut">
										{{item.title}}
									</view>
									<view class="text-sm margin-top-xs text-666">
										{{item.typeName}}
									</view>
									<view class="text-666 text-xs margin-top-sm">
										<text>阅读{{item.readNum}}</text>
										<text class="margin-left-sm">下载{{item.downNum}}</text>
									</view>
								</view>
							</view>
							<view class="padding-sm">
								<image v-if="item.fileType==3" :src="item.fileUrl" mode="" class="width-sub"
									style="height: 348rpx;"></image>
								<view v-if="item.fileType==3" class="text-cut-2 text-15 text-333 margin-top-sm">
									{{item.title}}
								</view>
								<view class="flex justify-between align-center margin-top-sm">
									<view class="flex justify-start align-center">
										<image :src="item.headImg" mode="" class="round"
											style="width: 34rpx;height: 34rpx;min-width: 34rpx;"></image>
										<view class="" style="margin-left: 12rpx;">
											{{item.nickName}}
										</view>
									</view>
									<view class="" v-if="is_flag">
										<view class="color" v-if="!item.price">
											免费
										</view>
										<view class="color" v-else>
											{{item.payStatus?'已付费':'付费'}}
										</view>
									</view>

								</view>
							</view>

						</view>
						<view
							@click="toPage('/filePage/pages/program-video/program-video?index=' + index+'&id=' + item.id  +'&typeId=' + TabCur + '&typeChildId=' + classificationId + '&typeName=' + typeName,item)"
							v-else class="item position-relative bg-white margin-top-sm radius5 width-sub">
							<image :src="baseUrl + '/static/Play.png'" mode=""
								style="position: absolute;top: 18rpx;right: 18rpx;width: 42rpx;height: 42rpx;z-index: 2;">
							</image>
							<view v-if="item.price" class="bg-color text-sm text-white radius10"
								style="position: absolute;top: 20rpx;left: 20rpx;z-index: 2;padding: 4rpx 20rpx;">
								<text v-if="item.payStatus">已付费</text>
								<text v-else>付费</text>
							</view>
							<!-- <view v-if="nav_type==2" class="flex justify-center align-center"
								style="background: rgba(0,0,0,.5);width: 126rpx;height: 42rpx;position: absolute;top: 20rpx;left: 20rpx;z-index: 2;">
								<view class="round"
									style="width: 10rpx;height: 10rpx;background: #16D91F;margin-right: 14rpx;">

								</view>
								<view class="text-sm text-white">
									直播中
								</view>
							</view> -->
							<!-- <view v-if="nav_type==2" class="text-sm text-white"
								style="position: absolute;top: 306rpx;left: 20rpx;z-index: 2;">
								520人在看
							</view> -->
							<!--  #ifdef  MP-WEIXIN-->
							<video :src="item.fileUrl" :controls="false" :show-center-play-btn="false"
								object-fit="cover" class="width-sub"></video>
							<!--  #endif -->

							<!--  #ifdef  APP-PLUS-->
							<image :src="item.coverUrl" class="width-sub" style="height: 348rpx;" />
							</image>
							<!--  #endif -->
							<view class="padding-sm">
								<view class="text-cut-2 text-15 text-333">
									{{item.title}}
								</view>
								<view class="flex justify-between align-center margin-top-sm">
									<view class="flex justify-start align-center text-cut">
										<image :src="item.headImg" mode="" class="round"
											style="width: 34rpx;height: 34rpx;min-width: 34rpx;">
										</image>
										<view class="" style="margin-left: 12rpx;">
											{{item.nickName}}
										</view>
									</view>
									<view class="color text-cut">
										{{item.typeName}}
									</view>
								</view>
							</view>

						</view>
					</view>
				</view>
				<view class="right" style="width: 348rpx;min-width: 348rpx;">
					<view class="" v-for="(item,index) in right_list">
						<view
							@click="toPage('/filePage/pages/file-detail/file-detail?id=' + item.id + '&nav_type=' + nav_type,item)"
							v-if="item.fileType!=1"
							class="item position-relative bg-white margin-top-sm width-sub radius5">
							<view v-if="item.fileType==2"
								class="flex justify-start align-center margin-top-sm padding-sm">
								<image :src="baseUrl+'/static/businessschool1.png'" mode=""
									style="width: 48rpx;height: 66rpx;margin: 24rpx 30rpx 0;"></image>
								<view class="text-cut">
									<view class="text-15 text-bold text-cut">
										{{item.title}}
									</view>
									<view class="text-sm margin-top-xs text-666">
										{{item.typeName}}
									</view>
									<view class="text-666 text-xs margin-top-sm">
										<text>阅读{{item.readNum}}</text>
										<text class="margin-left-sm">下载{{item.downNum}}</text>
									</view>
								</view>
							</view>
							<view class="padding-sm">
								<image v-if="item.fileType==3" :src="item.fileUrl" mode="" class="width-sub"
									style="height: 348rpx;"></image>
								<view v-if="item.fileType==3" class="text-cut-2 text-15 text-333 margin-top-sm">
									{{item.title}}
								</view>
								<view class="flex justify-between align-center margin-top-sm">
									<view class="flex justify-start align-center">
										<image :src="item.headImg" mode="" class="round"
											style="width: 34rpx;height: 34rpx;min-width: 34rpx;"></image>
										<view class="" style="margin-left: 12rpx;">
											{{item.nickName}}
										</view>
									</view>
									<view class="" v-if="is_flag">
										<view class="color" v-if="!item.price">
											免费
										</view>
										<view class="color" v-else>
											{{item.payStatus?'已付费':'付费'}}
										</view>
									</view>

								</view>
							</view>

						</view>
						<view
							@click="toPage('/filePage/pages/program-video/program-video?index=' + index+'&id=' + item.id +'&typeId=' + TabCur + '&typeChildId=' + classificationId + '&typeName=' + typeName,item)"
							v-else class="item position-relative bg-white margin-top-sm radius5 width-sub">
							<image :src="baseUrl + '/static/Play.png'" mode=""
								style="position: absolute;top: 18rpx;right: 18rpx;width: 42rpx;height: 42rpx;z-index: 2;">
							</image>
							<view v-if="item.price" class="bg-color text-sm text-white radius10"
								style="position: absolute;top: 20rpx;left: 20rpx;z-index: 2;padding: 4rpx 20rpx;">
								<text v-if="item.payStatus">已付费</text>
								<text v-else>付费</text>
							</view>
							<!-- 	<view v-if="nav_type==2" class="flex justify-center align-center"
								style="background: rgba(0,0,0,.5);width: 126rpx;height: 42rpx;position: absolute;top: 20rpx;left: 20rpx;z-index: 2;">
								<view class="round"
									style="width: 10rpx;height: 10rpx;background: #16D91F;margin-right: 14rpx;">

								</view>
								<view class="text-sm text-white">
									直播中
								</view>
							</view>
							<view v-if="nav_type==2" class="text-sm text-white"
								style="position: absolute;top: 306rpx;left: 20rpx;z-index: 2;">
								520人在看
							</view> -->
							<!--  #ifdef  MP-WEIXIN-->
							<video :src="item.fileUrl" :controls="false" :show-center-play-btn="false"
								object-fit="cover" class="width-sub"></video>
							<!--  #endif -->

							<!--  #ifdef  APP-PLUS-->
							<image :src="item.coverUrl" class="width-sub" style="height: 348rpx;"></image>
							<!--  #endif -->
							<view class="padding-sm">
								<view class="text-cut text-15 text-333">
									{{item.title}}
								</view>
								<view class="flex justify-between align-center margin-top-sm">
									<view class="flex justify-start align-center text-cut">
										<image :src="item.headImg" mode="" class="round"
											style="width: 34rpx;height: 34rpx;min-width: 34rpx;">
										</image>
										<view class="" style="margin-left: 12rpx;">
											{{item.nickName}}
										</view>
									</view>
									<view class="color text-cut">
										{{item.typeName}}
									</view>
								</view>
							</view>

						</view>
					</view>
				</view>

			</view>
			<view class="" v-else>
				<view v-for="item in list"
					class="flex justify-start align-center padding-sm bg-white margin-top-sm radius10"
					@click.stop="toPage('/filePage/pages/course/course?id=' + item.id,1)">
					<image :src="item.coverImg" class="radius5" mode=""
						style="width: 220rpx;min-width: 220rpx;height: 220rpx;"></image>
					<view class="margin-left-sm f-grow1">
						<view class="text-15 text-333 text-cut-2 text-bold" style="height: 79rpx;min-height: 79rpx;">
							{{item.title}}
						</view>
						<view class="text-sm text-999 margin-top-xs">
							{{item.typeName}}
						</view>
						<view class="flex justify-between align-center margin-top-xs">
							<view class="">
								<view class="color text-sm">
									¥ <text
										class="text-bold text-17">{{parseFloat(item.courseFee/100).toFixed(2)}}</text>
								</view>
								<view class="text-xs text-999 margin-top-xs">
									<text>已报名 {{item.downNum}}</text><text class="margin-left">浏览
										{{item.readNum}}</text>
								</view>
							</view>
							<button @click.stop="toPage('/filePage/pages/apply/apply?id=' + item.id,1)"
								class="bg-color text-15 text-white padding-bottom-xs padding-top-xs padding-left-sm padding-right-sm round">{{item.price?'立即报名':'免费报名'}}</button>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- </scroll-view> -->
		<uni-load-more :status="loading" />
		<view class="cu-modal" :class="modalName=='ModalAuthor'?'show':''">
			<view class="cu-dialog bg-white">
				<view class="cu-bar justify-end">
					<view class="content">提示</view>
				</view>
				<view class="padding-xl text-20">
					请先授权登录
				</view>
				<view class="flex justify-between align-center padding text-lg">
					<view @click="hideModal" class="bg-D7D7D7 text-gray radius5" style="padding: 32rpx 96rpx;">
						取消
					</view>
					<button v-if='canIUseProfile==false' open-type="getUserInfo" @getuserinfo="getUserInfo"
						class="bg-color text-white radius5" style="padding: 32rpx 96rpx;">
						确定
					</button>
					<button v-else @tap="getUserInfo" class="bg-color text-white radius5" style="padding: 32rpx 96rpx;">
						确定
					</button>
				</view>
			</view>
		</view>
		<view class="cu-modal" :class="{show:isShow}">
			<view class="cu-dialog bg-white">
				<view class="cu-bar justify-end">
					<view class="content">提示</view>
				</view>
				<view class="padding-xl text-20">
					获取用户手机号
				</view>
				<view class="flex justify-between align-center padding text-lg">
					<view @click="isShow=false" class="bg-D7D7D7 text-gray radius5" style="padding: 32rpx 96rpx;">
						取消
					</view>
					<button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber"
						class="bg-color text-white radius5" style="padding: 32rpx 96rpx;">
						确定
					</button>


				</view>
			</view>
		</view>
		<view class="cu-modal" :class="{show:payShow}">
			<view class="cu-dialog bg-white">
				<view class="cu-bar justify-end">
					<image @click="payShow=false" class="margin-right" :src="baseUrl + '/static/close2.png'" mode=""
						style="width: 28rpx;height: 28rpx;min-width: 28rpx;min-height: 28rpx;"></image>
				</view>
				<view class="padding text-xl color">
					￥{{ nav_type==2?parseFloat(payItem.chargeAmount / 100).toFixed(2):parseFloat(payItem.price / 100).toFixed(2)}}
				</view>
				<view class="text-15 text-333 text-bold padding flex justify-start align-center">
					<text class="margin-left">请选择支付方式</text>

				</view>
				<view @click="openPwd" class="text-15 text-333 text-bold padding flex justify-start align-center">
					<image class="margin-right-sm margin-left" :src="baseUrl + '/static/we-chat-pay3.png'" mode=""
						style="width: 44rpx;height: 44rpx;"></image>
					<view class="">
						<text>余额支付 </text>
						<!-- <text class="text-999">(余额不足）</text> -->
					</view>
				</view>
				<view @click="videoPay" class="text-15 text-333 text-bold padding flex justify-start align-center">
					<image class="margin-right-sm margin-left" :src="baseUrl + '/static/we-chat-pay2.png'" mode=""
						style="width: 44rpx;height: 44rpx;"></image>
					<view class="">
						微信支付
					</view>
				</view>
			</view>
		</view>
		<passkeyborad :money="money" @message='message' @close='close' :show="showPwd"></passkeyborad>
	</view>
</template>

<script>
	import BetterPull from '@/common/libs/BetterPull'
	import passkeyborad from '@/components/yzc-paykeyboard/yzc-paykeyboard.vue'
	export default {
		components: {
			passkeyborad
		},
		mixins: [
			BetterPull({
				async getPage(page, done) {

					this.loading = 'loading';
					// if (!this.classificationId) return done([]);
					let param
					if (this.title) {
						param = {
							pageNum: page,
							pageSize: 10,
							status: 1,
							typeId: this.TabCur,
							typeChildId: this.classificationId,
							typeName: this.typeName,
							title: this.title
						}
					} else {
						param = {
							pageNum: page,
							pageSize: 10,
							status: 1,
							typeId: this.TabCur,
							typeName: this.typeName,
							typeChildId: this.classificationId
						}
					}
					const [err, res] = await this.$get(this.url, param)
					// console.log(param)
					if (res) {
						// console.log(res)
						var data = res.data.list
						this.data = res.data
						done(data);
						if (data.length < 10) {
							this.loading = 'noMore';
						} else {
							this.loading = 'more';
						}
						if (this.nav_type == 3) {
							this.right_list = []
							this.left_list = []
							this.list.forEach((item, index) => {
								// item.coverUrl = item.fileUrl.split(',')[0]

								if (index % 2 == 0) {
									this.left_list.push(item)
								} else {
									this.right_list.push(item)

								}
							})
						}
						// console.log(this.loading) 
						// console.log(this.left_list)
					}
					if (err) {
						done([]);
						this.loading = 'noMore';
					}
				}
			})
		],
		data() {
			return {
				baseUrl: 'https://super.zoyob.com',
				loading: 'more',
				TabCur: '',
				TabCurName: '',
				typeName: '',
				scrollLeft: 0,
				nav_type: 1,
				url: this.$api.vod_list,
				data: '',
				classification1: [],
				classification2: [],
				classificationId: '',
				is_show: false,
				title: '',
				list: [],
				right_list: [],
				left_list: [],
				pageUrl: '',
				modalName: null,
				latitude: '',
				longitude: '',
				canIUseProfile: false,
				is_live: false,
				isShow: false,
				session_key: '',
				phoneNumber: "",
				payShow: false,
				payItem: {},
				money: 0,
				showPwd: false,
				is_flag: '',
				defaultImage: '/static/default.png'
			};
		},
		onLoad() {
			if (wx.getUserProfile) {
				// console.log('--check getUserProfile--OK');
				this.canIUseProfile = true;
			}
			// this.getClassification()
		},
		onShow() {

			let that = this
			// if (uni.getStorageSync('mobile')) {
			// 	this.phoneNumber = uni.getStorageSync('mobile')
			// }
			uni.getLocation({
				type: "gcj02",
				success: function(res) {
					that.latitude = res.latitude;
					that.longitude = res.longitude;
					// uni.getStorage({
					// 	key: 'userId',
					// 	success: function() {
					that.getClassification()
					that.getFlag()
					// 		that.getUser()

					// if (!that.phoneNumber) {
					// 	that.isShow = true
					// }
					// 	},
					// 	fail: function() {
					// 		// #ifdef MP-WEIXIN
					// 		that.modalName = "ModalAuthor";
					// 		// #endif
					// 	}
					// })
					uni.getStorage({
						key: 'userInfo',
						success: function(e) {
							// console.log(e.data)
							if (e.data.platformUserStatus || e.data.providerStatus || e.data
								.operatorStauts) {
								that.is_live = true
							} else {
								that.is_live = false
							}
						},
						fail: function() {}
					})
				},
				fail: function(err) {
					that.$util.msg('请允许定位')
					setTimeout(() => {
						uni.switchTab({
							url: "/pages/home/home"
						})
					}, 1500)

				}
			});
		},
		// onHide() {
		// 	console.log('********')
		// 	this.close()
		// },
		methods: {
			// async refreshMs() {
			// 	this.list = []
			// 	this.right_list = []
			// 	this.left_list = []
			// 	this.loading = 'loading';
			// 	// if (!this.classificationId) return done([]);
			// 	let param
			// 	if (this.title) {
			// 		param = {
			// 			pageNum: 1,
			// 			pageSize: 10,
			// 			status: 1,
			// 			typeId: this.TabCur,
			// 			typeChildId: this.classificationId,
			// 			typeName: this.typeName,
			// 			title: this.title
			// 		}
			// 	} else {
			// 		param = {
			// 			pageNum: 1,
			// 			pageSize: 10,
			// 			status: 1,
			// 			typeId: this.TabCur,
			// 			typeName: this.typeName,
			// 			typeChildId: this.classificationId
			// 		}
			// 	}
			// 	const [err, res] = await this.$get(this.url, param)
			// 	console.log(param)
			// 	if (res) {
			// 		console.log(res)
			// 		console.log(res.data.list)
			// 		var data = res.data.list
			// 		this.data = res.data
			// 		this.list = this.list.concat(res.data.list)

			// 		if (data.length < 10) {
			// 			this.loading = 'noMore';
			// 		} else {
			// 			this.loading = 'more';
			// 		}
			// 		if (this.nav_type == 3) {
			// 			this.right_list = []
			// 			this.left_list = []
			// 			this.list.forEach((item, index) => {
			// 				// item.coverUrl = item.fileUrl.split(',')[0]

			// 				if (index % 2 == 0) {
			// 					this.left_list.push(item)
			// 				} else {
			// 					this.right_list.push(item)

			// 				}
			// 			})
			// 		}
			// 		// console.log(this.loading) 
			// 		console.log(this.left_list)
			// 	}
			// },


			async getFlag() {
				const [err, res] = await this.$get(this.$api.hiddenFlag);
				if (res) {
					this.is_flag = res.data;
					if(this.is_flag==0){
						this.nav_type=3
						this.list = []
						this.right_list = []
						this.left_list = []
					uni.startPullDownRefresh()
					// console.log(this.is_flag==0)
					}
					
					uni.setStorage({
						key: 'is_flag',
						data: res.data
					})
					
				}
			},
			openPwd() {
				this.payShow = false
				this.showPwd = true
			},
			close() {
				this.showPwd = false
			},
			async message(password) {
				console.log(password)
				let that = this
				var CusBase64 = require('@/common/js/base64.js');
				//函数调用
				var passWord = CusBase64.CusBASE64.encoder(password);
				this.$get(this.$api.verifyPayPassWord, {
					passWord,
					userId: uni.getStorageSync('userId')
				}).then(res => {
					const [err, rs] = res
					if (rs) {
						that.balancePay()
					}
					if (err) {
						this.showPwd = false
						if (err.message == '请去设置密码！') {
							setTimeout(() => {
								uni.navigateTo({
									url: '/pagesA/pages/setPassword/setPassword'
								})
							}, 1500)
						}
					}
				})

			},
			async balancePay() {
				let that = this
				let type
				uni.showLoading({
					title: '正在支付',
					mask: true
				});

				if (that.nav_type == 3) {
					type = 1
				} else if (that.nav_type == 2) {
					type = 2
				} else {
					type = 3
				}
				const [e, r] = await that.$post(that.$api.video_create, {
					type: type,
					relateId: that.payItem.id
				})
				if (r) {
					const [er1, re1] = await this.$post(this.$api.video_accountPay, {
						orderId: r.data.id
					})
					if (re1) {
						that.$util.msg(re1.data)
						this.showPwd = false
						that.$util.openNewPage(that.pageUrl)
					}
					if (er1) {
						this.showPwd = false
					}
				}
			},
			search() {
				this.list = []
				this.right_list = []
				this.left_list = []
				uni.startPullDownRefresh();
			},
			async getUserInfo() {
				let that = this
				// this.hideModal()
				this.modalName = null
				uni.login({
					provider: 'weixin',
					success: function(loginRes) {
						// console.log(loginRes.code);
						// 获取用户信息
						uni.getUserInfo({
							provider: 'weixin',
							success: function(infoRes) {
								// console.log(infoRes.userInfo.nickName);
								// console.log(infoRes.userInfo.avatarUrl)
								that.getLogin(loginRes.code, infoRes.userInfo.nickName, infoRes
									.userInfo.avatarUrl)
							}
						});
					}
				});
			},
			async getLogin(code, nickName, avatarUrl) {
				uni.showLoading({
					title: '正在登录',
					mask: true
				});
				const [err, res] = await this.$post(this.$api.loginWX, {
					code: code,
					nickname: nickName,
					headimg: avatarUrl,
					latitude: this.latitude,
					longitude: this.longitude
				})
				if (res) {
					this.isShow = true
					this.session_key = res.data.session_key
					uni.setStorage({
						key: 'session_key',
						data: res.data.session_key
					})

					// console.log(res)
					uni.setStorage({
						key: 'token',
						data: res.data.openid
					})
					uni.setStorage({
						key: 'userId',
						data: res.data.userId
					})
					uni.setStorage({
						key: "openid",
						data: res.data.openid,
					});
					uni.hideLoading();
					this.getClassification()
					this.getUser()
					// this.list = []
					// uni.startPullDownRefresh()
					this.$util.msg(res.message)
				}
			},
			hideModal() {
				this.modalName = null
				uni.switchTab({
					url: '/pages/home/home'
				})
			},
			changeNavType(e) {
				this.nav_type = e
				if (e == 1) {
					this.url = this.$api.vod_list
					// console.log(e)
				} else if (e == 2) {
					this.url = this.$api.live_list
					// console.log(e)
				} else if (e == 3) {
					this.url = this.$api.programme_list
					// console.log(e)
				} else {
					this.url = this.$api.training_cliList
				}
				this.TabCur = ''
				this.typeName = ''
				this.classificationId = ''
				// if(this.TabCur){
				this.getClassification()
				// }

				// this.list = []
				// this.refreshMs()
			},
			changeclassification(e) {
				console.log(2222)
				this.classificationId = e
				this.open_show()

				this.list = []
				this.right_list = []
				this.left_list = []
				uni.startPullDownRefresh();
			},
			open_show() {
				this.is_show = !this.is_show
			},

			toPage(url, item) {
				console.log(11111)
				this.pageUrl = url
				let that = this
				// console.log(item)
				uni.getStorage({
					key: 'userId',
					success: function() {
						if (item == 1) {
							that.$util.openNewPage(url)
						} else {
							that.payItem = item
							if (!item.payStatus && that.nav_type != 4) {
								console.log(  that.nav_type+'收费' + item.chargeAmount)
								if(that.nav_type == 2){
									that.money = item.chargeAmount
								}else{
									that.money = item.price
								}
								
								that.payShow = true
							} else {
								that.$util.openNewPage(url)
							}
						}
						// if (!that.phoneNumber) {
						// 	that.isShow = true
						// }else{
						// 	if (item == 1) {
						// 		that.$util.openNewPage(url)
						// 	} else {
						// 		if (!item.payStatus && that.nav_type != 4) {
						// 			// console.log('收费')
						// 			that.videoPay(item.id)
						// 		} else {
						// 			that.$util.openNewPage(url)
						// 		}
						// 	}
						// }

					},
					fail: function() {
						// #ifdef MP-WEIXIN
						that.modalName = "ModalAuthor";
						// #endif

						// #ifdef APP-PLUS
						uni.navigateTo({
							url: '/pages/login/login'
						})
						// #endif
					}
				})


			},
			tabSelect(e, index) {
				if (e == "") {
					this.TabCur = e
					this.scrollLeft = (index - 1) * 60
					this.classificationId = ''
					this.typeName = ''
					this.title = ''
					this.list = []
					this.right_list = []
					this.left_list = []
					uni.startPullDownRefresh();
				} else {
					if (this.TabCur == e.id) {
						this.open_show()
					} else {
						this.TabCur = e.id;
						this.scrollLeft = (index - 1) * 60
						this.TabCurName = e.name
						if (this.nav_type == 1 || this.nav_type == 3) {
							this.getClassification2()
						} else {
							this.list = []
							this.right_list = []
							this.left_list = []
							uni.startPullDownRefresh();
						}

					}
				}

				// this.list = []
				// uni.startPullDownRefresh()
			},
			async videoPay() {
				uni.showLoading({
					title: '正在支付',
					mask: true
				});
				let that = this
				let type
				if (this.nav_type == 3) {
					type = 1
				} else if (this.nav_type == 2) {
					type = 2
				} else {
					type = 3
				}
				const [err, res] = await this.$post(this.$api.video_create, {
					type: type,
					relateId: this.payItem.id
				})
				if (res) {
					console.log(res)
					// #ifdef  MP-WEIXIN
					const data = {
						orderId: res.data.id,
						payWay: 1,
						appId: this.$config.wxAppId,
						openId: uni.getStorageSync('openid')

					};
					// #endif


					// #ifdef  APP-PLUS
					const data = {
						orderId: res.data.id,
						payWay: 2,
						appId: this.$config.appId,
						openId: uni.getStorageSync('openid')
					};
					// #endif
					const [er, re] = await this.$get(this.$api.video_wxPay, data)
					if (re) {
						console.log(re)
						const data = re.data;
						uni.hideLoading();
						// #ifdef  MP-WEIXIN
						uni.requestPayment({
							provider: "wxpay",
							appId: data.appId,
							timeStamp: data.timeStamp,
							nonceStr: data.nonceStr,
							package: data._package,
							signType: data.signType,
							paySign: data.paySign,
							success: function(res) {
								that.$util.openNewPage(that.pageUrl)
							},
							fail: function(err) {
								console.log("fail:" + JSON.stringify(err));
							},
						});
						// #endif

						// #ifdef  APP-PLUS
						uni.requestPayment({
							"provider": "wxpay",
							"orderInfo": {
								"appid": data.appId, // 微信开放平台 - 应用 - AppId，注意和微信小程序、公众号 AppId 可能不一致
								"noncestr": data.nonceStr, // 随机字符串
								"package": data._package, // 固定值
								"partnerid": data.partnerid, // 微信支付商户号
								"prepayid": data.prepayid, // 统一下单订单号 
								"timestamp": data.timeStamp, // 时间戳（单位：秒）
								"sign": data.sign // 签名，这里用的 MD5 签名
							},
							success(res) {
								that.$util.openNewPage(that.pageUrl)
							},
							fail(e) {}
						})
						// #endif
					}
				}
			},
			async getClassification() {
				this.list = []
				this.right_list = []
				this.left_list = []
				let type
				if (this.nav_type == 1) {
					type = 3
				} else if (this.nav_type == 2) {
					type = 4
				} else if (this.nav_type == 3) {
					type = 5
				} else {
					type = 7
				}
				const [err, res] = await this.$get(this.$api.home_categoryTreeList, {
					type: type
				})
				if (res) {
					this.classification1 = res.data
					// if (res.data.length > 0) {
					// 	this.TabCur = res.data[0].id
					// 	this.TabCurName = res.data[0].name

					// }
					if (this.TabCur) {
						this.getClassification2()
					} else {

						uni.startPullDownRefresh();
					}

				}
			},
			async getClassification2() {
				let type
				if (this.nav_type == 1) {
					type = 3
				} else if (this.nav_type == 2) {
					type = 4
				} else if (this.nav_type == 3) {
					type = 5
				} else {
					type = 7
				}
				const [err, res] = await this.$get(this.$api.home_productCateList, {
					parentId: this.TabCur,
					type: type
				})
				if (res) {
					this.classification2 = res.data
					if (res.data.length > 0) {
						this.classificationId = res.data[0].id
						this.typeName = this.TabCurName + res.data[0].name

					}
					this.list = []
					uni.startPullDownRefresh();
				}


			},
			async getUser() {
				const [err, rs] = await this.$get(this.$api.userDetail)
				if (rs) {
					// console.log(rs)
					uni.setStorageSync('userInfo', rs.data);
				}
			},
			async getPhoneNumber(e) {
				this.isShow = false
				console.log(e)
				var iv = e.detail.iv;
				var encryptedData = e.detail.encryptedData;
				var session_key;
				if (uni.getStorageSync('session_key')) {
					session_key = uni.getStorageSync('session_key')
				} else {
					session_key = this.session_key
				}
				const data = {
					session_key,
					iv,
					encryptedData
				}
				const [err, rs] = await this.$get(this.$api.getWXPhone, data)
				if (rs) {
					this.$util.msg(rs.message)
					this.phoneNumber = rs.data.mobile
					uni.setStorageSync('mobile', rs.data.mobile)
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.nav {
		.on {
			border-bottom: 6rpx solid #ED7200;
		}

		view {
			border-bottom: 6rpx solid #fff;
		}
	}
</style>
